package com.zx.viewlearn.views.touchEvent;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;

/**
 * Created by zhoux on 2018/1/12.
 * 注释：事件拦截机制学习
 * E/touchEvent: MyViewGroupA dispatchTouchEvent
 * E/touchEvent: MyViewGroupA onInterceptTouchEvent
 * E/touchEvent: MyViewGroupB dispatchTouchEvent
 * E/touchEvent: MyViewGroupB onInterceptTouchEvent
 * E/touchEvent: MyView dispatchTouchEvent
 * E/touchEvent: MyView onInterceptTouchEvent
 * E/touchEvent: MyView onTouchEvent
 * E/touchEvent: MyViewGroupB onTouchEvent
 * E/touchEvent: MyViewGroupA onTouchEvent
 */

public class MyView extends View {
    String TAG = MyView.class.getSimpleName();

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
//        Log.e("touchEvent", TAG + " dispatchTouchEvent");//事件调度，分发，先不管
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.e("touchEvent", TAG + " onTouchEvent");
        return super.onTouchEvent(event);//true ：当前view拦截touch事件，父控件不会执行 onTouchEvent方法。 false：不会拦截touch事件,父控件仍然会执行 onTouchEvent方法
    }
}
